package com.tencreat.service.pt.impl;


import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tencreat.common.core.domain.model.ReqIdParam;
import com.tencreat.common.core.domain.model.ReqIdsParam;
import com.tencreat.domain.pt.MallPtUserAuto;
import com.tencreat.mapper.pt.MallPtUserAutoMapper;
import com.tencreat.service.pt.IMallPtUserAutoService;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 用户自动拼团列Service业务层处理
 *
 * @author tencreat
 * @date 2021-12-15
 */
@Service
public class MallPtUserAutoServiceImpl extends ServiceImpl<MallPtUserAutoMapper, MallPtUserAuto> implements IMallPtUserAutoService {


    /**
     * 查询用户自动拼团列
     *
     * @param id 用户自动拼团列ID
     * @return 用户自动拼团列
     */
    @Override
    public MallPtUserAuto selectMallPtUserAutoById(ReqIdParam id) {
        return baseMapper.selectById(id.getId());
    }

    /**
     * 查询用户自动拼团列列表
     *
     * @param mallPtUserAuto 用户自动拼团列
     * @return 用户自动拼团列
     */
    @Override
    public List<MallPtUserAuto> selectMallPtUserAutoList(MallPtUserAuto mallPtUserAuto) {
        return baseMapper.selectList(Wrappers.query(mallPtUserAuto));
    }

    /**
     * 新增用户自动拼团列
     *
     * @param mallPtUserAuto 用户自动拼团列
     * @return 结果
     */
    @Override
    public int insertMallPtUserAuto(MallPtUserAuto mallPtUserAuto) {
        mallPtUserAuto.setCreateTime(LocalDateTime.now());
        return baseMapper.insert(mallPtUserAuto);
    }

    /**
     * 修改用户自动拼团列
     *
     * @param mallPtUserAuto 用户自动拼团列
     * @return 结果
     */
    @Override
    public int updateMallPtUserAuto(MallPtUserAuto mallPtUserAuto) {
        mallPtUserAuto.setUpdateTime(LocalDateTime.now());
        return baseMapper.updateById(mallPtUserAuto);
    }

    /**
     * 批量删除用户自动拼团列
     *
     * @param ids 需要删除的用户自动拼团列ID
     * @return 结果
     */
    @Override
    public int deleteMallPtUserAutoByIds(ReqIdsParam ids) {
        return baseMapper.deleteBatchIds(ids.getId());
    }

    /**
     * 删除用户自动拼团列信息
     *
     * @param id 用户自动拼团列ID
     * @return 结果
     */
    @Override
    public int deleteMallPtUserAutoById(ReqIdParam id) {
        return baseMapper.deleteById(id.getId());
    }

    @Override
    public boolean autoPt(Long ptId, Long uuid,Long ptGoodsId,Integer addressId) {
        MallPtUserAuto mallPtUserAuto = new MallPtUserAuto();
        mallPtUserAuto.setUuid(uuid);
        mallPtUserAuto.setPtGoodsId(ptGoodsId);
        mallPtUserAuto.setPtId(ptId);
        mallPtUserAuto.setAddressId(addressId);
        mallPtUserAuto.setStatus(true);
        mallPtUserAuto.setCreateTime(LocalDateTime.now());
        mallPtUserAuto.setUpdateTime(LocalDateTime.now());
        return baseMapper.insert(mallPtUserAuto) > 0;
    }
}
